﻿@model IEnumerable<GPI.Models.GPI_PROJECT>

@{
    ViewBag.Title = "Liste des projets";
    bool open = ViewBag.open;
    bool prof = ViewBag.Prof;
    string projectsState = "";
}


@if (prof && open)
{
    projectsState = "(période de proposition fermée)";
}
else if (!prof && !open)
{
    projectsState = "(période d'inscription fermée)";
}

<h2>Liste des projets @projectsState</h2>
<p>
  @if (!open && prof)
  {
        @Html.ActionLink("Créer un nouveau projet", "Create")
  }
</p>

@if (prof)
{
    @:<input type="checkbox" id="checkbox" /> N'afficher que mes projets<br /><br />
}
<table id="tableProj">
    <tr>
        <th>
            Titre
        </th>
        <th>
            Nb étudiants max
        </th>
        <th>
            Année
        </th>
        @if (prof)
        {
            <th>
                Prof.
            </th>
        }
        <th>
            Client
        </th>
        <th></th>
    </tr>

@foreach (var item in Model)
{
    bool creator = User.Identity.Name.Equals(item.FK_Prof);
    <tr>
        @if (!creator)
        {
            <td style="display:none;">
                hideMe
            </td>
        }    
        <td>
            @Html.DisplayFor(modelItem => item.title)
            @if (creator)
            {
                @: (créateur)
            }
            @if (!prof && item.PK_Project == ViewBag.CrtStudentProjectID)
            {
                @: (inscrit)
            }
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.max_students)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.YEAR)
        </td>
            @if (prof)
            {
                <td>
                    @Html.DisplayFor(modelItem => item.GPI_PROF.last_name)
                </td>
            }
        <td>
            @Html.DisplayFor(modelItem => item.GPI_PROF1.last_name)
        </td>
        <td>
            @Html.ActionLink("Détails", "Details", new { id = item.PK_Project })

            @if (!open && prof && creator)
            {
                @:| @Html.ActionLink("Modifier", "Edit", new { id = item.PK_Project })
                @:| @Html.ActionLink("Supprimer", "Delete", new { id = item.PK_Project })
            }
        </td>
    </tr>
}

</table>
<br />
@if (prof)
{
    using (Html.BeginForm("Index", "InscriptionList"))
    {
        <button type="submit">Liste d'inscriptions</button>
    }
    using (Html.BeginForm("Index", "GroupList"))
    {
        <button type="submit">Liste des groupes</button>
    }
}

<script type="text/javascript">
    $(document).ready(function () {
        var filter = "hideMe";
        $("#checkbox").click(function () {
            if ($(this).is(":checked")) {
                $("#tableProj").find("td:contains(" + filter + ")").parent().hide();
            } else {
                $("#tableProj").find("td:contains(" + filter + ")").parent().show();
            }
        });
    });
    
</script>